import { createRequestWithPrefix } from '../axios.js';

const requestUser = (...args) => {
  return createRequestWithPrefix('user')(...args)
    .then(({ data }) => data);
};

async function register({ username, password, email }) {
  return requestUser('post', '/', {
    username,
    password,
    email
  });
}

async function login({ loginName, password }) {
  return requestUser('post', '/login', {
    loginName,
    password
  });
}

async function logout() {
  return requestUser('post', '/logout');
}

async function getInfo() {
  return requestUser('get', '/');
}

async function unique({ username, email }) {
  return requestUser('post', '/unique', {
    username, email
  });
}

async function del() {
  return requestUser('delete', '/');
}

export {
  register,
  login,
  logout,
  getInfo,
  unique,
  del
};
